<template>
  <div style="width:100%;height:auto; margin:0 auto;">
    <el-form ref="ruleForm" :model="form" label-width="100px" label-position="left">

      <el-form-item>
        <div slot="label">上级目录<font color="red">*</font></div>
        <el-input v-model="form.parentName" maxlength="20" show-word-limit placeholder="上级目录名称" :readonly="true" />
      </el-form-item>

      <el-form-item>
        <div slot="label">目录名称<font color="red">*</font></div>
        <el-input v-model="form.typeName" maxlength="20" show-word-limit placeholder="目录名称" />
      </el-form-item>

      <el-form-item>
        <div slot="label">排序号</div>
        <el-input v-model="form.sortNum" maxlength="20" show-word-limit placeholder="排序号"/>
      </el-form-item>

    </el-form>
    <div style="margin-top:10px;text-align:center;">
      <el-button type="primary" @click="save()">确定</el-button>
      <el-button type="danger" @click="closePage()">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getTreePersonalList, saveData, disabled } from '@/api/publicCatalog'

import {Message} from 'element-ui'

export default {
  inject: ['getList'],
  props: {
    proid: {
      type: String,
      required: true
    },
    proName: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      form: {
        flag: "U",
        parentId: '', // 父级 ID
        parentName: '', // 父级名称，只读显示
        typeName: '', // 目录名称
        sortNum: '' // 排序号
      }
    }
  },
  created() {
    this.form.parentId = this.proid
    this.form.parentName = this.proName
    console.log(this.form, "!!!!!")
  },
    methods: {
    save() { // 新增
      if (!this.form.typeName) {
        this.$message.error('分类名称不能为空')
        return
      } else {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(255,255,255,0.1)'
        })

        this.form.parentId = this.proid
        saveData(this.form).then(response => {
          Message({
            message: '新增成功',
            type: 'success',
            duration: 5 * 1000
          })
          this.$emit('update:visible', false)
          loading.close()
          this.getList()
        }).catch(response => {
          loading.close()
          this.getList()
        })
      }
    },
    closePage() {
      this.$emit('update:visible', false)
      // this.getList()
    }
  }
}
</script>
